package com.marvin.springBoot.configuration.dataSource;

//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Qualifier;
//import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.context.annotation.Primary;
//import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
//import org.springframework.orm.jpa.JpaTransactionManager;
//import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
//import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
//import org.springframework.transaction.PlatformTransactionManager;
//
//import javax.repository.EntityManagerFactory;
//import javax.sql.DataSource;
/**
 * @author marvin.ma
 * @create 2017-09-26 9:31
 * @desc jpa 配置文件
 **/
//@Configuration
//@EnableJpaRepositories(value = "com.marvin.springBoot.repository",
//        entityManagerFactoryRef = "writeEntityManagerFactory",
//        transactionManagerRef="writeTransactionManager")
public class WriteDataSourceConfig {
    //
    //@Autowired
    //JpaProperties jpaProperties;
    //
    //@Autowired
    //@Qualifier("writeDruidDataSource")
    //private DataSource writeDruidDataSource;
    //
    ///**
    // * EntityManagerFactory类似于Hibernate的SessionFactory,mybatis的SqlSessionFactory
    // * 总之,在执行操作之前,我们总要获取一个EntityManager,这就类似于Hibernate的Session,
    // * mybatis的sqlSession.
    // * @return
    // */
    ////@Bean(name = "writeEntityManagerFactory")
    ////@Primary
    ////public EntityManagerFactory writeEntityManagerFactory() {
    ////    HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
    ////    LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
    ////    factory.setJpaVendorAdapter(vendorAdapter);
    ////    factory.setPackagesToScan("com.marvin.springBoot.persistence");
    ////    factory.setDataSource(writeDruidDataSource);//数据源
    ////    factory.setJpaPropertyMap(jpaProperties.getProperties());
    ////    factory.afterPropertiesSet();//在完成了其它所有相关的配置加载以及属性设置后,才初始化
    ////    return factory.getObject();
    ////}
    //
    //
    ///**
    // * 我们通过LocalContainerEntityManagerFactoryBean来获取EntityManagerFactory实例
    // * @return
    // */
    //@Bean(name = "writeEntityManagerFactoryBean")
    //@Primary
    //public LocalContainerEntityManagerFactoryBean writeEntityManagerFactoryBean(EntityManagerFactoryBuilder builder) {
    //    return builder
    //            .dataSource(writeDruidDataSource)
    //            .properties(jpaProperties.getProperties())
    //            .packages("com.marvin.springBoot.persistence") //设置实体类所在位置
    //            .persistenceUnit("writePersistenceUnit")
    //            .build();
    //    //.getObject();//不要在这里直接获取EntityManagerFactory
    //}
    //
    ///**
    // * EntityManagerFactory类似于Hibernate的SessionFactory,mybatis的SqlSessionFactory
    // * 总之,在执行操作之前,我们总要获取一个EntityManager,这就类似于Hibernate的Session,
    // * mybatis的sqlSession.
    // * @param builder
    // * @return
    // */
    //@Bean(name = "writeEntityManagerFactory")
    //@Primary
    //public EntityManagerFactory writeEntityManagerFactory(EntityManagerFactoryBuilder builder) {
    //    return this.writeEntityManagerFactoryBean(builder).getObject();
    //}
    //
    ///**
    // * 配置事物管理器
    // * @return
    // */
    //@Bean(name = "writeTransactionManager")
    //@Primary
    //public PlatformTransactionManager writeTransactionManager(EntityManagerFactoryBuilder builder) {
    //    return new JpaTransactionManager(writeEntityManagerFactory(builder));
    //}
}
